package org.projectwithoutname.ui.wizard;

import magick.ImageInfo;
import magick.ImageMagick;
import magick.MagickImage;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.projectwithoutname.application.CriarThumbnail;
import org.projectwithoutname.commons.Commons;
import org.projectwithoutname.ui.wizard.pages.ImagePage;

public class ImageHandlerWizard extends Wizard implements INewWizard {
	IWorkbench workbench;
	IStructuredSelection selection;
	private ImagePage imagePage;
	private ImageData imageData = null;
	
	public ImageHandlerWizard(ImageData imageData){
		this.imageData = imageData;
	}
	
	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		this.workbench = workbench;
		this.selection = selection;
	}
	
	@Override
	public void addPages() {
		imagePage = new ImagePage("Select Avatar", imageData);
		addPage(imagePage);
	}

	
	@Override
	public boolean performFinish() {
		Rectangle rectangle = imagePage.getRectangle();
		System.out.println("Rectangle: "+rectangle);
//		imageData = new ImageData("C:\\Users\\Johnny\\Desktop\\images\\selection.jpg");
		imageData = new ImageData("C:\\Documents and Settings\\jpqueiroz\\Desktop\\selection.jpg");
		ImageData data = imagePage.getImageData();
		imageData = imageData.scaledTo(rectangle.width - rectangle.x, rectangle.height - rectangle.y);
		
		int x = 0;
		for(int i=rectangle.x;i<rectangle.width; i++){
			int y = 0;
			for(int j=rectangle.y;j<rectangle.height; j++){
				imageData.setPixel(x, y, data.getPixel(i, j));
				y++;
			}
			x++;
		}
		return true;
	}
	
	public ImageData getCut(){
		return imageData;
	}
	
	
}
